﻿using FriendStar.Application.MainData;
using FriendStar.Application.WareHouse;
using FriendStar.Code;
using FriendStar.Domain.Entity.WareHouse;
using FriendStar.Repository.Infrastructure;
using System;
using System.Web.Mvc;

namespace FriendStar.Web.Areas.WareHouse.Controllers
{
    public class ConsignmentController : ControllerBase
    {
        //
        // GET: /WareHouse/Consignment/
        private string useUnit = Configs.GetValue("UseUnit");

        private string factoryFlag = Configs.GetValue("FactoryFlag");

        private string curUser = OperatorProvider.Provider.GetCurrent().UserName;

        private string MYDESC = "台账日期寄售";

        ConsignmentApp app = new ConsignmentApp();
        BUS_SJ_DictionaryApp bus_sj_dictionaryApp = new BUS_SJ_DictionaryApp();
        ZSJ_B1_GH_SupplierInformationApp zsj_b1_gh_supplierinformationApp = new ZSJ_B1_GH_SupplierInformationApp();
        V_ZSJ_11_LJ_Production_JGApp v_zsj_11_lj_production_jgApp = new V_ZSJ_11_LJ_Production_JGApp();
        CPK_ZD_11_DatStoreHouseApp cpk_zd_11_datstorehouseApp = new CPK_ZD_11_DatStoreHouseApp();
        V_JSK_12_MX_StoLJKListAccoApp v_jsk_12_mx_stoljklistaccoApp = new V_JSK_12_MX_StoLJKListAccoApp();
        V_JSK_14_MX_StoLJKListAcco_MidApp v_jsk_14_mx_stoljklistacco_midApp = new V_JSK_14_MX_StoLJKListAcco_MidApp();
        V_JSK_16_MX_StoLJKListAcco_ArcApp v_jsk_16_mx_stoljklistacco_arcApp = new V_JSK_16_MX_StoLJKListAcco_ArcApp();
        JSK_11_ML_StoLJKConAccoApp jsk_11_ml_stoljkconaccoApp = new JSK_11_ML_StoLJKConAccoApp();
        JSK_12_MX_StoLJKListAccoApp jsk_12_mx_stoljklistaccoApp = new JSK_12_MX_StoLJKListAccoApp();

        #region 入库

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ConsignmentEnter(string status)
        {
            status = string.IsNullOrEmpty(status) ? "0" : status;
            ViewBag.status = status;
            ViewBag.fhappencomList = zsj_b1_gh_supplierinformationApp.GetList("UnitNO = UseUnit");
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P6");
            string accountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            ViewBag.accountDate = accountDate;
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetConsignmentEnterListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            var data = new
            {
                rows = v_jsk_12_mx_stoljklistaccoApp.GetList(pagination, "JR", FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetConsignmentEnterDocListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            string AccountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            if (AccountDate == FAccountDate)
            {
                var data = new
                {
                    rows = v_jsk_14_mx_stoljklistacco_midApp.GetList(pagination, "JR", FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
            else
            {
                var data = new
                {
                    rows = v_jsk_16_mx_stoljklistacco_arcApp.GetList(pagination, "JR", FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ConsignmentEnterInput(string status, string number)
        {
            ViewBag.status = status != "B" ? "I" : status;
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fhappencomList = zsj_b1_gh_supplierinformationApp.GetList("UnitNO = UseUnit");
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList("JR");
            ViewBag.fdocunoTemp = GetDocumentNum.GetNum(useUnit, factoryFlag, "寄售入库", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitConsignmentEnterForm(string status, JSK_11_ML_StoLJKConAccoEntity entity, string detail, string keyValue)
        {
            JSK_12_MX_StoLJKListAccoEntity detailEntity = null;
            if (entity != null)
            {
                entity.FDocuTypeNO = "JR";
                entity.FAccountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "正式");
                detailEntity = detail.ToObject<JSK_12_MX_StoLJKListAccoEntity>();
            }
            if (status == "I")
            {
                bool result = false;
                string DocNum = "";
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, entity.FAccountDate, entity.FDocuTypeNO, entity.FDocuNO, entity.FCurDate, entity.FHappenComNO, "", "", detailEntity.FProductionNO, detailEntity.FQuantity, detailEntity.FPrice, detailEntity.FStoreNO, "", OperatorProvider.Provider.GetCurrent().UserCode, entity.FCredence, entity.FDescription, detailEntity.FDescription, factoryFlag, "寄售入库", "正式", "", "21", out DocNum);
                if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                {
                    entity.FDocuNO = DocNum;
                }
                if (result)
                {
                    return Success("入库信息输入操作成功。", entity);
                }
                else
                {
                    return Error("入库信息输入操作失败。");
                }
            }
            else if (status == "D")
            {
                bool result = false;
                string DocNum = "";
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, "", "", "", "", "", "", keyValue, "", null, null, "", "", OperatorProvider.Provider.GetCurrent().UserCode, "", "", "", factoryFlag, "寄售入库", "正式", "", "23", out DocNum);
                if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                {
                    entity.FDocuNO = DocNum;
                }
                if (result)
                {
                    return Success("入库信息删除操作成功。", entity);
                }
                else
                {
                    return Error("入库信息删除操作失败。");
                }
            }
            else if (status == "U")
            {
                bool result = false;
                string DocNum = "";
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, "", "", "", "", "", "", detailEntity.FDocuListID, "", detailEntity.FQuantity, detailEntity.FPrice, "", "", OperatorProvider.Provider.GetCurrent().UserCode, "", "", "", factoryFlag, "寄售入库", "正式", "", "22", out DocNum);
                if (result)
                {
                    return Success("入库信息修改操作成功。", entity);
                }
                else
                {
                    return Error("入库信息修改操作失败。");
                }
            }
            else if (status == "P")
            {
                bool result = false;
                string DocNum = "";
                foreach (string item in keyValue.Split(','))
                {
                    result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, "", "", item, "", "", "", "", "", null, null, "", "", OperatorProvider.Provider.GetCurrent().UserCode, "", "", "", factoryFlag, "寄售入库", "正式", "", "24", out DocNum);
                }
                if (result)
                {
                    return Success("入库信息审核操作成功。", entity);
                }
                else
                {
                    return Error("入库信息审核操作失败。");
                }
            }
            else if (status == "C")
            {
                V_JSK_14_MX_StoLJKListAcco_MidEntity midEntity = v_jsk_14_mx_stoljklistacco_midApp.GetForm(keyValue);
                if (midEntity.FQuantity.HasValue && midEntity.FQuantity.Value > 0)
                {
                    bool result = false;
                    string DocNum = "";
                    result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, "", "", "", "", "", "", keyValue, "", null, null, "", "", OperatorProvider.Provider.GetCurrent().UserCode, "", "", "", factoryFlag, "寄售入库", "正式", "", "25", out DocNum);
                    if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                    {
                        entity.FDocuNO = DocNum;
                    }
                    if (result)
                    {
                        return Success("入库信息冲红操作成功。", entity);
                    }
                    else
                    {
                        return Error("当前库存不足，入库信息冲红操作失败。");
                    }
                }
                else
                {
                    return Error("当前单据为冲红单，不可再进行冲红操作。");
                }
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ConsignmentEnterOrder(string number)
        {
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fhappencomList = zsj_b1_gh_supplierinformationApp.GetList("UnitNO = UseUnit");
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P6");
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList("JR");
            //ViewBag.fdocunoTemp = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "寄售入库", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            //ViewBag.fproductionList = v_zsj_11_lj_production_jgApp.GetList("");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetConsignmentEnterListByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = new
                {
                    rows = v_jsk_12_mx_stoljklistaccoApp.GetListByDocuNO("JR", FDocuNO)
                };
                result = data.ToJson();
            }
            else
            {
                FAccountDate = FAccountDate.Replace("-", "");
                string AccountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = new
                    {
                        rows = v_jsk_14_mx_stoljklistacco_midApp.GetListByDocuNO("JR", FDocuNO)
                    };
                    result = data.ToJson();
                }
                else
                {
                    var data = new
                    {
                        rows = v_jsk_16_mx_stoljklistacco_arcApp.GetListByDocuNO("JR", FDocuNO)
                    };
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetConsignmentEnterItemByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = v_jsk_12_mx_stoljklistaccoApp.GetItemByDocuNO("JR", FDocuNO);
                result = data.ToJson();
            }
            else
            {
                FAccountDate = FAccountDate.Replace("-", "");
                string AccountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = v_jsk_14_mx_stoljklistacco_midApp.GetItemByDocuNO("JR", FDocuNO);
                    result = data.ToJson();
                }
                else
                {
                    var data = v_jsk_16_mx_stoljklistacco_arcApp.GetItemByDocuNO("JR", FDocuNO);
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        #endregion

        #region 出库

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ConsignmentOut(string status)
        {
            status = string.IsNullOrEmpty(status) ? "0" : status;
            ViewBag.status = status;
            ViewBag.fhappencomList = zsj_b1_gh_supplierinformationApp.GetList("IsCustomer ='1'");
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P6");
            string accountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            ViewBag.accountDate = accountDate;
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetConsignmentOutListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            var data = new
            {
                rows = v_jsk_12_mx_stoljklistaccoApp.GetList(pagination, "JC", FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetConsignmentOutDocListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            string AccountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            if (AccountDate == FAccountDate)
            {
                var data = new
                {
                    rows = v_jsk_14_mx_stoljklistacco_midApp.GetList(pagination, "JC", FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
            else
            {
                var data = new
                {
                    rows = v_jsk_16_mx_stoljklistacco_arcApp.GetList(pagination, "JC", FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ConsignmentOutInput(string status, string number)
        {
            ViewBag.status = status != "B" ? "I" : status;
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fhappencomList = zsj_b1_gh_supplierinformationApp.GetList("UseUnit ='" + useUnit + "' AND IsCustomer ='1'");
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList("JC");
            ViewBag.fdocunoTemp = GetDocumentNum.GetNum(useUnit, factoryFlag, "寄售出库", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitConsignmentOutForm(string status, JSK_11_ML_StoLJKConAccoEntity entity, string detail, string keyValue)
        {
            JSK_12_MX_StoLJKListAccoEntity detailEntity = null;
            if (entity != null)
            {
                entity.FDocuTypeNO = "JC";
                entity.FAccountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "正式");
                detailEntity = detail.ToObject<JSK_12_MX_StoLJKListAccoEntity>();
            }
            if (status == "I")
            {
                bool result = false;
                string DocNum = "";
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, entity.FAccountDate, entity.FDocuTypeNO, entity.FDocuNO, entity.FCurDate, entity.FHappenComNO, "", "", detailEntity.FProductionNO, detailEntity.FQuantity, detailEntity.FPrice, detailEntity.FStoreNO, "", OperatorProvider.Provider.GetCurrent().UserCode, entity.FCredence, entity.FDescription, detailEntity.FDescription, factoryFlag, "寄售出库", "正式", "", "11", out DocNum);
                if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                {
                    entity.FDocuNO = DocNum;
                }
                if (result)
                {
                    return Success("出库信息输入操作成功。", entity);
                }
                else
                {
                    return Error("当前库存不足，出库输入操作失败。");
                }
            }
            else if (status == "D")
            {
                bool result = false;
                string DocNum = "";
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, "", "", "", "", "", "", keyValue, "", null, null, "", "", OperatorProvider.Provider.GetCurrent().UserCode, "", "", "", factoryFlag, "寄售出库", "正式", "", "13", out DocNum);
                if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                {
                    entity.FDocuNO = DocNum;
                }
                if (result)
                {
                    return Success("出库信息删除操作成功。", entity);
                }
                else
                {
                    return Error("出库信息删除操作失败。");
                }
            }
            else if (status == "U")
            {
                bool result = false;
                string DocNum = "";
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, "", "", "", "", "", "", detailEntity.FDocuListID, "", detailEntity.FQuantity, detailEntity.FPrice, "", "", OperatorProvider.Provider.GetCurrent().UserCode, "", "", "", factoryFlag, "寄售出库", "正式", "", "12", out DocNum);
                if (result)
                {
                    return Success("出库信息修改操作成功。", entity);
                }
                else
                {
                    return Error("出库信息修改操作失败。");
                }
            }
            else if (status == "P")
            {
                bool result = false;
                string DocNum = "";
                foreach (string item in keyValue.Split(','))
                {
                    result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, "", "", item, "", "", "", "", "", null, null, "", "", OperatorProvider.Provider.GetCurrent().UserCode, "", "", "", factoryFlag, "寄售出库", "正式", "", "14", out DocNum);
                }
                if (result)
                {
                    return Success("出库信息审核操作成功。", entity);
                }
                else
                {
                    return Error("出库信息审核操作失败。");
                }
            }
            else if (status == "C")
            {
                V_JSK_14_MX_StoLJKListAcco_MidEntity midEntity = v_jsk_14_mx_stoljklistacco_midApp.GetForm(keyValue);
                if (midEntity.FQuantity.HasValue && midEntity.FQuantity.Value > 0)
                {
                    bool result = false;
                    string DocNum = "";
                    result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, "", "", "", "", "", "", keyValue, "", null, null, "", "", OperatorProvider.Provider.GetCurrent().UserCode, "", "", "", factoryFlag, "寄售入库", "正式", "", "25", out DocNum);
                    if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                    {
                        entity.FDocuNO = DocNum;
                    }
                    if (result)
                    {
                        return Success("出库信息冲红操作成功。", entity);
                    }
                    else
                    {
                        return Error("出库信息冲红操作失败。");
                    }
                }
                else
                {
                    return Error("当前单据为冲红单，不可再进行冲红操作。");
                }
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ConsignmentOutOrder(string number)
        {
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fhappencomList = zsj_b1_gh_supplierinformationApp.GetList("UseUnit ='" + useUnit + "' AND IsCustomer ='1'");
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P6");
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList("JC");
            //ViewBag.fproductionList = v_zsj_11_lj_production_jgApp.GetList("");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetConsignmentOutListByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = new
                {
                    rows = v_jsk_12_mx_stoljklistaccoApp.GetListByDocuNO("JC", FDocuNO)
                };
                result = data.ToJson();
            }
            else
            {
                FAccountDate = FAccountDate.Replace("-", "");
                string AccountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = new
                    {
                        rows = v_jsk_14_mx_stoljklistacco_midApp.GetListByDocuNO("JC", FDocuNO)
                    };
                    result = data.ToJson();
                }
                else
                {
                    var data = new
                    {
                        rows = v_jsk_16_mx_stoljklistacco_arcApp.GetListByDocuNO("JC", FDocuNO)
                    };
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetConsignmentOutItemByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = v_jsk_12_mx_stoljklistaccoApp.GetItemByDocuNO("JC", FDocuNO);
                result = data.ToJson();
            }
            else
            {
                FAccountDate = FAccountDate.Replace("-", "");
                string AccountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = v_jsk_14_mx_stoljklistacco_midApp.GetItemByDocuNO("JC", FDocuNO);
                    result = data.ToJson();
                }
                else
                {
                    var data = v_jsk_16_mx_stoljklistacco_arcApp.GetItemByDocuNO("JC", FDocuNO);
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        #endregion

        #region 废品件更换

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ConsignmentWaste(string status)
        {
            status = string.IsNullOrEmpty(status) ? "0" : status;
            ViewBag.status = status;
            ViewBag.fhappencomList = zsj_b1_gh_supplierinformationApp.GetList("UnitNO = UseUnit");
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P6");
            string accountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            ViewBag.accountDate = accountDate;
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetConsignmentWasteListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            var data = new
            {
                rows = v_jsk_12_mx_stoljklistaccoApp.GetList(pagination, "JS", FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetConsignmentOutWasteListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            string AccountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            if (AccountDate == FAccountDate)
            {
                var data = new
                {
                    rows = v_jsk_14_mx_stoljklistacco_midApp.GetList(pagination, "JS", FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
            else
            {
                var data = new
                {
                    rows = v_jsk_16_mx_stoljklistacco_arcApp.GetList(pagination, "JS", FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ConsignmentWasteInput(string status, string number)
        {
            ViewBag.status = status != "B" ? "I" : status;
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fhappencomList = zsj_b1_gh_supplierinformationApp.GetList("UnitNO = UseUnit");
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList("JS");
            ViewBag.fdocunoTemp = GetDocumentNum.GetNum(useUnit, factoryFlag, "寄售更换", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitConsignmentWasteForm(string status, JSK_11_ML_StoLJKConAccoEntity entity, string detail, string keyValue)
        {
            JSK_12_MX_StoLJKListAccoEntity detailEntity = null;
            if (entity != null)
            {
                entity.FDocuTypeNO = "JS";
                entity.FAccountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "正式");
                detailEntity = detail.ToObject<JSK_12_MX_StoLJKListAccoEntity>();
            }
            if (status == "I")
            {
                bool result = false;
                string DocNum = "";
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, entity.FAccountDate, entity.FDocuTypeNO, entity.FDocuNO, entity.FCurDate, entity.FHappenComNO, "", "", detailEntity.FProductionNO, detailEntity.FQuantity, detailEntity.FPrice, detailEntity.FStoreNO, "", OperatorProvider.Provider.GetCurrent().UserCode, entity.FCredence, entity.FDescription, detailEntity.FDescription, factoryFlag, "寄售更换", "正式", "", "31", out DocNum);
                if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                {
                    entity.FDocuNO = DocNum;
                }
                if (result)
                {
                    return Success("废品件更换信息输入操作成功。", entity);
                }
                else
                {
                    return Error("废品件更换信息输入操作失败。");
                }
            }
            else if (status == "D")
            {
                bool result = false;
                string DocNum = "";
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, "", "", "", "", "", "", keyValue, "", null, null, "", "", OperatorProvider.Provider.GetCurrent().UserCode, "", "", "", factoryFlag, "寄售更换", "正式", "", "33", out DocNum);
                if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                {
                    entity.FDocuNO = DocNum;
                }
                if (result)
                {
                    return Success("废品件更换信息删除操作成功。", entity);
                }
                else
                {
                    return Error("废品件更换信息删除操作失败。");
                }
            }
            else if (status == "U")
            {
                bool result = false;
                string DocNum = "";
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, "", "", "", "", "", "", detailEntity.FDocuListID, "", detailEntity.FQuantity, detailEntity.FPrice, "", "", OperatorProvider.Provider.GetCurrent().UserCode, "", "", "", factoryFlag, "寄售更换", "正式", "", "32", out DocNum);
                if (result)
                {
                    return Success("废品件更换信息修改操作成功。", entity);
                }
                else
                {
                    return Error("废品件更换信息修改操作失败。");
                }
            }
            else if (status == "P")
            {
                bool result = false;
                string DocNum = "";
                foreach (string item in keyValue.Split(','))
                {
                    result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, "", "", item, "", "", "", "", "", null, null, "", "", OperatorProvider.Provider.GetCurrent().UserCode, "", "", "", factoryFlag, "寄售更换", "正式", "", "34", out DocNum);
                }
                if (result)
                {
                    return Success("废品件更换信息审核操作成功。", entity);
                }
                else
                {
                    return Error("废品件更换信息审核操作失败。");
                }
            }
            else if (status == "C")
            {
                V_JSK_14_MX_StoLJKListAcco_MidEntity midEntity = v_jsk_14_mx_stoljklistacco_midApp.GetForm(keyValue);
                if (midEntity.FQuantity.HasValue && midEntity.FQuantity.Value > 0)
                {
                    bool result = false;
                    string DocNum = "";
                    result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, "", "", "", "", "", "", keyValue, "", null, null, "", "", OperatorProvider.Provider.GetCurrent().UserCode, "", "", "", factoryFlag, "寄售入库", "正式", "", "25", out DocNum);
                    if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                    {
                        entity.FDocuNO = DocNum;
                    }
                    if (result)
                    {
                        return Success("废品件更换信息冲红操作成功。", entity);
                    }
                    else
                    {
                        return Error("当前库存不足，废品件更换信息冲红操作失败。");
                    }
                }
                else
                {
                    return Error("当前单据为冲红单，不可再进行冲红操作。");
                }
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ConsignmentWasteOrder(string number)
        {
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fhappencomList = zsj_b1_gh_supplierinformationApp.GetList("UnitNO = UseUnit");
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P6");
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList("JS");
            //ViewBag.fproductionList = v_zsj_11_lj_production_jgApp.GetList("");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetConsignmentWasteListByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = new
                {
                    rows = v_jsk_12_mx_stoljklistaccoApp.GetListByDocuNO("JS", FDocuNO)
                };
                result = data.ToJson();
            }
            else
            {
                FAccountDate = FAccountDate.Replace("-", "");
                string AccountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = new
                    {
                        rows = v_jsk_14_mx_stoljklistacco_midApp.GetListByDocuNO("JS", FDocuNO)
                    };
                    result = data.ToJson();
                }
                else
                {
                    var data = new
                    {
                        rows = v_jsk_16_mx_stoljklistacco_arcApp.GetListByDocuNO("JS", FDocuNO)
                    };
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetConsignmentWasteItemByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = v_jsk_12_mx_stoljklistaccoApp.GetItemByDocuNO("JS", FDocuNO);
                result = data.ToJson();
            }
            else
            {
                FAccountDate = FAccountDate.Replace("-", "");
                string AccountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = v_jsk_14_mx_stoljklistacco_midApp.GetItemByDocuNO("JS", FDocuNO);
                    result = data.ToJson();
                }
                else
                {
                    var data = v_jsk_16_mx_stoljklistacco_arcApp.GetItemByDocuNO("JS", FDocuNO);
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        #endregion

        #region 盘点

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ConsignmentShelves(string status)
        {
            status = string.IsNullOrEmpty(status) ? "0" : status;
            ViewBag.status = status;
            ViewBag.fhappencomList = zsj_b1_gh_supplierinformationApp.GetList("UnitNO = UseUnit");
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P6");
            string accountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            ViewBag.accountDate = accountDate;
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetConsignmentShelvesListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            var data = new
            {
                rows = v_jsk_12_mx_stoljklistaccoApp.GetList(pagination, "JP", FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetConsignmentShelvesDocListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            string AccountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            if (AccountDate == FAccountDate)
            {
                var data = new
                {
                    rows = v_jsk_14_mx_stoljklistacco_midApp.GetList(pagination, "JP", FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
            else
            {
                var data = new
                {
                    rows = v_jsk_16_mx_stoljklistacco_arcApp.GetList(pagination, "JP", FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ConsignmentShelvesInput(string status, string number)
        {
            ViewBag.status = status != "B" ? "I" : status;
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fhappencomList = zsj_b1_gh_supplierinformationApp.GetList("UnitNO = UseUnit");
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList("JP");
            ViewBag.fdocunoTemp = GetDocumentNum.GetNum(useUnit, factoryFlag, "寄售盘存", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitConsignmentShelvesForm(string status, JSK_11_ML_StoLJKConAccoEntity entity, string detail, string keyValue)
        {
            JSK_12_MX_StoLJKListAccoEntity detailEntity = null;
            if (entity != null)
            {
                entity.FDocuTypeNO = "JP";
                entity.FAccountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "正式");
                detailEntity = detail.ToObject<JSK_12_MX_StoLJKListAccoEntity>();
            }
            if (status == "I")
            {
                bool result = false;
                string DocNum = "";
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, entity.FAccountDate, entity.FDocuTypeNO, entity.FDocuNO, entity.FCurDate, entity.FHappenComNO, "", "", detailEntity.FProductionNO, detailEntity.FQuantity, detailEntity.FPrice, detailEntity.FStoreNO, "", OperatorProvider.Provider.GetCurrent().UserCode, entity.FCredence, entity.FDescription, detailEntity.FDescription, factoryFlag, "寄售盘存", "正式", "", "41", out DocNum);
                if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                {
                    entity.FDocuNO = DocNum;
                }
                if (result)
                {
                    return Success("盘存信息输入操作成功。", entity);
                }
                else
                {
                    return Error("盘存信息输入操作失败。");
                }
            }
            else if (status == "D")
            {
                bool result = false;
                string DocNum = "";
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, "", "", "", "", "", "", keyValue, "", null, null, "", "", OperatorProvider.Provider.GetCurrent().UserCode, "", "", "", factoryFlag, "寄售盘存", "正式", "", "43", out DocNum);
                if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                {
                    entity.FDocuNO = DocNum;
                }
                if (result)
                {
                    return Success("盘存信息删除操作成功。", entity);
                }
                else
                {
                    return Error("盘存信息删除操作失败。");
                }
            }
            else if (status == "U")
            {
                bool result = false;
                string DocNum = "";
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, "", "", "", "", "", "", detailEntity.FDocuListID, "", detailEntity.FQuantity, detailEntity.FPrice, "", "", OperatorProvider.Provider.GetCurrent().UserCode, "", "", "", factoryFlag, "寄售盘存", "正式", "", "42", out DocNum);
                if (result)
                {
                    return Success("盘存信息修改操作成功。", entity);
                }
                else
                {
                    return Error("盘存信息修改操作失败。");
                }
            }
            else if (status == "P")
            {
                bool result = false;
                string DocNum = "";
                foreach (string item in keyValue.Split(','))
                {
                    result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, "", "", item, "", "", "", "", "", null, null, "", "", OperatorProvider.Provider.GetCurrent().UserCode, "", "", "", factoryFlag, "寄售盘存", "正式", "", "44", out DocNum);
                }
                if (result)
                {
                    return Success("盘存信息审核操作成功。", entity);
                }
                else
                {
                    return Error("盘存信息审核操作失败。");
                }
            }
            else if (status == "C")
            {
                V_JSK_14_MX_StoLJKListAcco_MidEntity midEntity = v_jsk_14_mx_stoljklistacco_midApp.GetForm(keyValue);
                if (midEntity.FQuantity.HasValue && midEntity.FQuantity.Value > 0)
                {
                    bool result = false;
                    string DocNum = "";
                    result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoJskStockCata(useUnit, "", "", "", "", "", "", keyValue, "", null, null, "", "", OperatorProvider.Provider.GetCurrent().UserCode, "", "", "", factoryFlag, "寄售入库", "正式", "", "25", out DocNum);
                    if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                    {
                        entity.FDocuNO = DocNum;
                    }
                    if (result)
                    {
                        return Success("盘存信息冲红操作成功。", entity);
                    }
                    else
                    {
                        return Error("当前库存不足，盘存信息冲红操作失败。");
                    }
                }
                else
                {
                    return Error("当前单据为冲红单，不可再进行冲红操作。");
                }
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult ConsignmentShelvesOrder(string number)
        {
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fhappencomList = zsj_b1_gh_supplierinformationApp.GetList("UnitNO = UseUnit");
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P6");
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList("JP");
            //ViewBag.fproductionList = v_zsj_11_lj_production_jgApp.GetList("");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetConsignmentShelvesListByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = new
                {
                    rows = v_jsk_12_mx_stoljklistaccoApp.GetListByDocuNO("JP", FDocuNO)
                };
                result = data.ToJson();
            }
            else
            {
                FAccountDate = FAccountDate.Replace("-", "");
                string AccountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = new
                    {
                        rows = v_jsk_14_mx_stoljklistacco_midApp.GetListByDocuNO("JP", FDocuNO)
                    };
                    result = data.ToJson();
                }
                else
                {
                    var data = new
                    {
                        rows = v_jsk_16_mx_stoljklistacco_arcApp.GetListByDocuNO("JP", FDocuNO)
                    };
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetConsignmentShelvesItemByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = v_jsk_12_mx_stoljklistaccoApp.GetItemByDocuNO("JP", FDocuNO);
                result = data.ToJson();
            }
            else
            {
                FAccountDate = FAccountDate.Replace("-", "");
                string AccountDate = GetDocumentNum.GetNum(useUnit, factoryFlag, "台账日期寄售", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = v_jsk_14_mx_stoljklistacco_midApp.GetItemByDocuNO("JP", FDocuNO);
                    result = data.ToJson();
                }
                else
                {
                    var data = v_jsk_16_mx_stoljklistacco_arcApp.GetItemByDocuNO("JP", FDocuNO);
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        #endregion

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetConsignmentSelectProductionJson(Pagination pagination, string FProductionNO)
        {
            var data = new
            {
                rows = v_zsj_11_lj_production_jgApp.GetList(pagination, FProductionNO),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult GetPrintDetailsData(bool isDefaultDate, bool isArchive, string ids)
        {
            var data = app.GetPrintDetailsData(isDefaultDate, isArchive, ids);

            return Success("获取打印数据成功。", data);
        }

        #region 台账

        public ActionResult ConsignmentLegter()
        {
            ViewData["LedgerDate"] = app.GetLedgerDate(useUnit, factoryFlag, MYDESC, curUser);

            ViewData["curUserName"] = OperatorProvider.Provider.GetCurrent().UserName;

            ViewData["curUnit"] = useUnit;

            ViewData["curDate"] = DateTime.Now.ToString("yyyy-MM-dd");

            ViewData["curTime"] = DateTime.Now.ToString("HH:mm:ss");

            return View();
        }
        #endregion

        #region 报表

        public ActionResult ConsignmentReport()
        {
            ViewData["LedgerDate"] = app.GetLedgerDate(useUnit, factoryFlag, MYDESC, curUser);

            ViewData["curUserName"] = OperatorProvider.Provider.GetCurrent().UserName;

            ViewData["curUnit"] = useUnit;

            ViewData["curDate"] = DateTime.Now.ToString("yyyy-MM-dd");

            ViewData["curTime"] = DateTime.Now.ToString("HH:mm:ss");

            return View();
        }

        public ActionResult ConsignmentComprehensive()
        {
            ViewData["LedgerDate"] = app.GetLedgerDate(useUnit, factoryFlag, MYDESC, curUser);

            ViewData["curUserName"] = OperatorProvider.Provider.GetCurrent().UserName;

            ViewData["curUnit"] = useUnit;

            ViewData["curDate"] = DateTime.Now.ToString("yyyy-MM-dd");

            ViewData["curTime"] = DateTime.Now.ToString("HH:mm:ss");

            return View();
        }

        public ActionResult ConsignmentLedgerDetails(string param, string FAccountDate)
        {
            ViewData["jsonData"] = param;

            ViewData["defaultDate"] = FAccountDate;

            ViewData["isDefaultDate"] = FAccountDate == app.GetLedgerDate(useUnit, factoryFlag, MYDESC, curUser);

            ViewData["curUserName"] = OperatorProvider.Provider.GetCurrent().UserName;

            ViewData["curUnit"] = useUnit;

            ViewData["curDate"] = DateTime.Now.ToString("yyyy/MM/dd");

            ViewData["curTime"] = DateTime.Now.ToString("HH:mm:ss");

            return View();
        }
        public ActionResult ConsignmentLedgerStatistics(string param, string FAccountDate)
        {
            ViewData["jsonData"] = param;

            ViewData["defaultDate"] = FAccountDate;

            ViewData["isDefaultDate"] = FAccountDate == app.GetLedgerDate(useUnit, factoryFlag, MYDESC, curUser);

            ViewData["curUserName"] = OperatorProvider.Provider.GetCurrent().UserName;

            ViewData["curUnit"] = useUnit;

            ViewData["curDate"] = DateTime.Now.ToString("yyyy/MM/dd");

            ViewData["curTime"] = DateTime.Now.ToString("HH:mm:ss");

            return View();
        }
        public ActionResult ConsignmentCommentIn()
        {
            return View();
        }

        public ActionResult ConsignmentCommentOut()
        {
            return View();
        }
        public ActionResult AddConsignmentCommentIn(string SJDH, string LBJH, string BSZM1)
        {
            var data = app.AddConsignmentCommentIn(SJDH, LBJH, BSZM1);

            return Content(data.ToJson());
        }

        public ActionResult AddConsignmentCommentOut(string SJDH, string LBJH, string BSZM2)
        {
            var data = app.AddConsignmentCommentOut(SJDH, LBJH, BSZM2);

            return Content(data.ToJson());
        }

        //GetConsignmentSADetails
        public ActionResult GetConsignmentSADetails(Pagination pagination, string FAccountDate, string FProductionNO, string FProductionTypeNO)
        {
            bool isDefaultDate = FAccountDate == app.GetLedgerDate(useUnit, factoryFlag, MYDESC, curUser);

            var data = new
            {
                rows = app.GetConsignmentSADetails(pagination, FAccountDate, FProductionNO, FProductionTypeNO, isDefaultDate),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };

            return Content(data.ToJson());
        }
        public ActionResult GetConsignmentExchangeArchivies(Pagination pagination, string FDocuTypeName, string FDocuNO, string FHappenComNO, string FCurDate, string FProductionNO, string FCredence, string FCurDates)
        {
            var data = new
            {
                rows = app.GetConsignmentExchangeArchivies(pagination, FDocuTypeName, FDocuNO, FHappenComNO, FCurDate, FProductionNO, FCredence, FCurDates),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };

            return Content(data.ToJson());
        }
        public ActionResult GetConsignmentInStockComparies(Pagination pagination, string FCurDate, string SJDH, string LBJH, string RKCY, string FCurDates)
        {
            var data = new
            {
                rows = app.GetConsignmentInStockComparies(pagination, FCurDate, SJDH, LBJH, RKCY, FCurDates),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };

            return Content(data.ToJson());
        }
        public ActionResult GetConsignmentOutStockComparies(Pagination pagination, string FCurDate, string SJDH, string LBJH, string RKCY, string FCurDates)
        {
            var data = new
            {
                rows = app.GetConsignmentOutStockComparies(pagination, FCurDate, SJDH, LBJH, RKCY, FCurDates),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };

            return Content(data.ToJson());
        }


        public ActionResult GetConsignmentLedgerDetails(Pagination pagination, string UseUnit, string FProductionNO, string FProductionName, string FPrice, string FAccountDate)
        {
            bool isDefaultDate = FAccountDate == app.GetLedgerDate(useUnit, factoryFlag, MYDESC, curUser);

            var data = new
            {
                rows = app.GetConsignmentLedgerDetails(pagination, FAccountDate, FProductionNO, UseUnit, isDefaultDate),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };

            return Content(data.ToJson());
        }

        public ActionResult GetConsignmentLedgerStatistics(Pagination pagination, string UseUnit, string FProductionNO, string FProductionName, string FPrice, string FAccountDate)
        {
            bool isDefaultDate = FAccountDate == app.GetLedgerDate(useUnit, factoryFlag, MYDESC, curUser);

            var data = new
            {
                rows = app.GetConsignmentLedgerStatistics(pagination, FAccountDate, FProductionNO, UseUnit, isDefaultDate),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };

            return Content(data.ToJson());
        }

        public ActionResult GetConsignmentInstocks(Pagination pagination, string FAccountDate, string FHappenComNO)
        {
            bool isDefaultDate = FAccountDate == app.GetLedgerDate(useUnit, factoryFlag, MYDESC, curUser);

            var data = new
            {
                rows = app.GetConsignmentInstocks(pagination, FAccountDate, FHappenComNO, isDefaultDate),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };

            return Content(data.ToJson());
        }
        public ActionResult GetConsignmentOutstocks(Pagination pagination, string FAccountDate, string FHappenComNO)
        {
            bool isDefaultDate = FAccountDate == app.GetLedgerDate(useUnit, factoryFlag, MYDESC, curUser);

            var data = new
            {
                rows = app.GetConsignmentOutstocks(pagination, FAccountDate, FHappenComNO, isDefaultDate),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };

            return Content(data.ToJson());
        }
        public ActionResult GetConsignmentInstockStatistics(Pagination pagination, string FAccountDate, string FHappenComNO, string FProductionNO)
        {
            bool isDefaultDate = FAccountDate == app.GetLedgerDate(useUnit, factoryFlag, MYDESC, curUser);

            var data = new
            {
                rows = app.GetConsignmentInstockStatistics(pagination, FAccountDate, FHappenComNO, isDefaultDate, FProductionNO),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };

            return Content(data.ToJson());
        }
        public ActionResult GetConsignmentOutstockStatistics(Pagination pagination, string FAccountDate, string FHappenComNO, string FProductionNO)
        {
            bool isDefaultDate = FAccountDate == app.GetLedgerDate(useUnit, factoryFlag, MYDESC, curUser);

            var data = new
            {
                rows = app.GetConsignmentOutstockStatistics(pagination, FAccountDate, FHappenComNO, isDefaultDate, FProductionNO),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };

            return Content(data.ToJson());
        }

        public ActionResult GetConsignmentCateSum(Pagination pagination, string FAccountDate, string FProductionTypeNO)
        {
            bool isDefaultDate = FAccountDate == app.GetLedgerDate(useUnit, factoryFlag, MYDESC, curUser);

            var data = new
            {
                rows = app.GetConsignmentCateSum(pagination, FAccountDate, FProductionTypeNO, isDefaultDate),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };

            return Content(data.ToJson());
        }

        public ActionResult GetConsignmentPartsSum(Pagination pagination, string FAccountDate, string FProductionNO)
        {
            bool isDefaultDate = FAccountDate == app.GetLedgerDate(useUnit, factoryFlag, MYDESC, curUser);

            var data = new
            {
                rows = app.GetConsignmentPartsSum(pagination, FAccountDate, FProductionNO, isDefaultDate),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };

            return Content(data.ToJson());
        }

        public ActionResult GetConsignmentreceiveAndDispatch(Pagination pagination, string FAccountDate, string FProductionNO)
        {
            var data = new
            {
                rows = app.GetConsignmentreceiveAndDispatch(pagination, FAccountDate, FProductionNO),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };

            return Content(data.ToJson());
        }

        public ActionResult GetFProductionTypies()
        {
            string FClassNO = "01";

            var data = app.GetFProductionTypies(FClassNO);

            return Content(data.ToJson());
        }
        public ActionResult GetDocuTypies()
        {
            string FClassNO = "33";

            var data = app.GetFProductionTypies(FClassNO);

            return Content(data.ToJson());
        }

        public ActionResult GetHappenComs()
        {

            var data = app.GetHappenComs();

            return Content(data.ToJson());
        }
        public ActionResult GetHappenComies()
        {

            var data = app.GetHappenComies();

            return Content(data.ToJson());
        }
        public ActionResult GetHappenComes()
        {
            var data = app.GetHappenComes();

            return Content(data.ToJson());
        }

        #endregion
    }
}
